package com.chensheng.dao;

import com.chensheng.enums.ProductStatusEnum;
import com.chensheng.model.ProductInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author:ChenSheng
 * @Description:
 * @Date: Created in 下午 15:35 2018/5/14 0014
 */
@Mapper
public interface ProductInfoDAO {

    @Select({"select * from product_info"})
    List<ProductInfo> selectAllInSale();

    @Select({"select * from product_info where product_id=#{productId}"})
    ProductInfo selectByProductId(@Param("productId") String productId);

    @Update({"update product_info set product_stock = product_stock - #{reduction} where product_id = #{productId}"})
    void decreaseStock(@Param("reduction") Integer reduction, @Param("productId") String productId);

    @Update({"update product_info set product_stock = product_stock + #{productQuantity} where product_id = #{productId}"})
    void increaseStock(@Param("productId") String productId, @Param("productQuantity") Integer productQuantity);

    @Select({"select * from product_info limit #{start},#{offset}"})
    List<ProductInfo> selectAll(@Param("start") Integer start, @Param("offset") Integer offset);

    @Select({"select count(product_id) from product_info"})
    Integer count();

    @Update({"update product_info set product_status=#{status} where product_id=#{productId}"})
    void setProductStatus(@Param("status") Integer productStatus, @Param("productId") String productId);

    @Insert({"insert product_info values (#{productId}, #{productName}, #{productPrice}, #{productStock}, #{productDescription}, " +
            "#{productIcon}, #{productStatus}, #{categoryType}, #{createTime}, #{updateTime})"})
    void insertOne(ProductInfo productInfo);

    @Update({"update product_info set product_name=#{productName}, product_price=#{productPrice}, product_stock=#{productStock}," +
            "product_description=#{productDescription}, product_icon=#{productIcon}, product_status=#{productStatus}, category_type=#{categoryType}," +
            "update_time=#{updateTime} where product_id=#{productId}"})
    void updateOne(ProductInfo productInfo);
}
